package com.hangim.pce.common.tree;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.google.common.collect.Lists;
import org.apache.commons.lang3.builder.ToStringBuilder;

import java.util.List;

/**
 * 树节点的值对象
 */
public class TreeNode {
    // 节点ID
    @JsonSerialize(using = ToStringSerializer.class)
    private long id;
    // 父节点ID
    @JsonSerialize(using = ToStringSerializer.class)
    private long pId;
    // 节点编号
    private String code;
    // 节点名称
    private String name;
    // 节点是否勾选
    private boolean checked;
    // 是否展开
    private boolean open;
    // 是否有子节点,如果值为true,那么节点展开时将会异步加载子节点
    private boolean isParent;
    // 是否禁用节点的checkbox和radio
    private boolean chkDisabled;
    // 子节点数量
    private int childrenCount;
    // 子节点集合
    private List<TreeNode> children = Lists.newArrayList();

    public TreeNode() {
    }

    public TreeNode(long id, long pId, String name) {
        this.id = id;
        this.pId = pId;
        this.name = name;
    }

    public boolean isOpen() {
        return open;
    }

    public void setOpen(boolean open) {
        this.open = open;
    }

    public boolean isParent() {
        return isParent;
    }

    public void setParent(boolean parent) {
        isParent = parent;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public long getpId() {
        return pId;
    }

    public void setpId(long pId) {
        this.pId = pId;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public boolean isChecked() {
        return checked;
    }

    public void setChecked(boolean checked) {
        this.checked = checked;
    }

    public boolean getIsParent() {
        return isParent;
    }

    public void setIsParent(boolean isParent) {
        this.isParent = isParent;
    }

    public boolean isChkDisabled() {
        return chkDisabled;
    }

    public void setChkDisabled(boolean chkDisabled) {
        this.chkDisabled = chkDisabled;
    }

    public int getChildrenCount() {
        return childrenCount;
    }

    public void setChildrenCount(int childrenCount) {
        this.childrenCount = childrenCount;
    }

    public List<TreeNode> getChildren() {
        return children;
    }

    public void setChildren(List<TreeNode> children) {
        this.children = children;
    }

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }
}

